local shenyin = fk.CreateSkill {
  name = "th_shenyin",
}

shenyin:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(shenyin.name) and data.firstTarget and
    data.card and #data:getAllTargets() == 1 and player == data.from then
      local other = data.to
      return other and other ~= player and not other:isNude()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local other = data.to
    local cards = room:askToChooseCards(player, {
      target = other,
      min = 1,
      max = 2,
      flag = "he",
      skill_name = shenyin.name,
      prompt = "#th_shenyin-invoke::" .. other.id
    })
    if #cards ~= 0 then
      room:moveCardTo(cards, Card.PlayerSpecial, other, fk.ReasonJustMove, shenyin.name, "$th_shenyin", false, player.id, nil, other.id)
      for _, cid in ipairs(cards) do
        local card = Fk:getCardById(cid)
        if card and card.type ~= Card.TypeBasic then
          player:drawCards(1, shenyin.name)
          break
        end
      end
    end
  end,
})
shenyin:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(shenyin.name) and data.firstTarget and
    data.card and #data:getAllTargets() == 1 and player == data.to then
      local other = data.from
      return other and other ~= player and not other:isNude()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local other = data.from
    local cards = room:askToChooseCards(player, {
      target = other,
      min = 1,
      max = 2,
      flag = "he",
      skill_name = shenyin.name,
      prompt = "#th_shenyin-invoke::" .. other.id
    })
    if #cards ~= 0 then
      room:moveCardTo(cards, Card.PlayerSpecial, other, fk.ReasonJustMove, shenyin.name, "$th_shenyin", false, player.id, nil, other.id)
      for _, cid in ipairs(cards) do
        local card = Fk:getCardById(cid)
        if card and card.type ~= Card.TypeBasic then
          player:drawCards(1, shenyin.name)
          break
        end
      end
    end
  end,
})

shenyin:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and #player:getPile("$th_shenyin") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player.id, player:getPile("$th_shenyin"), false, nil, player, shenyin.name)
  end,
})

Fk:loadTranslationTable{
  ["th_shenyin"] = "神隐",
  [":th_shenyin"] = "当你使用牌指定其他角色为唯一目标或成为其他角色使用牌的唯一目标后，你可以扣置其至多两张牌直到本回合结束，若其中有非基本牌，你摸一张牌。",

  ["#th_shenyin_delay"] = "神隐",
  ["#th_shenyin-invoke"] = "神隐：你可以扣置 %dest 两张牌直到回合结束，若其中有非基本牌，你摸一张牌。",

  ["$th_shenyin"] = "神隐",
}

return shenyin